Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RustOptimize to set optimize #112756

Merged
merged 3 commits into from
Jul 2, 2023

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Jun 18, 2023

close #112678

Use RustOptimize to set optimize.

@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2023

r? @clubby789

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 18, 2023
@Rustin170506 Rustin170506 marked this pull request as ready for review June 18, 2023 06:57
@Rustin170506 Rustin170506 force-pushed the rustin-patch-bootstrap branch 2 times, most recently from e0da899 to c382acb Compare June 18, 2023 07:14
@clubby789
Copy link
Contributor

clubby789 commented Jun 18, 2023

Instead of StringOrBool, why not make an enum that accepts only true, false and the actual possible values for opt-level (0, 1, 2, 3, s, z), so we can prevent incorrect opt-levels being configured?

@Rustin170506
Copy link
Member Author

Instead of StringOrBool, why not make an enum that accepts only true, false and the actual possible values for opt-level (0, 1, 2, 3, s, z), so we can prevent incorrect opt-levels being configured?

I followed this suggestion. #112678 (comment)

@clubby789
Copy link
Contributor

@Kobzol Any thoughts on the approach here?

@Kobzol
Copy link
Contributor

Kobzol commented Jun 18, 2023

Maybe for options parsing it could stay as StringOrBool and we can just validate supported options during parsing, like this.

But in the parsed config it would be much nicer to have it as an enum. The if let StringOrBool::Bool(true) | StringOrBool::String(_) check is currently duplicated at 4 places, but it's not immediately obvious that you should use this check to recognize a release build. It would be better if there was an enum with methods like is_release(&self) -> bool and get_opt_level(&self) -> Option<String>.

@Rustin170506 Rustin170506 force-pushed the rustin-patch-bootstrap branch from 32e4362 to b6d2cde Compare June 19, 2023 01:22
@Rustin170506
Copy link
Member Author

It would be better if there was an enum with methods like is_release(&self) -> bool and get_opt_level(&self) -> Option<String>.

Good suggestion! Thanks!

@Kobzol
Copy link
Contributor

Kobzol commented Jun 19, 2023

It's better now, thanks. I would suggest two more things:

  1. Create an enum and call the methods on it. config.is_release() is a bit more "global", maybe it should be e.g. config.rust_opt.is_release() or something like that.
  2. Perform the validation when creating the enum. When you now run bootstrap, but the get_opt_level method is not called (I'm not sure if it's called always), then you will not know that the provided value might be wrong. And then when you run a different command, suddenly it can fail.

But I'll let others chime in :) These are small details.

@clubby789
Copy link
Contributor

I agree with the above suggestions - I'd also like to ask if you can add a test to validate the new behaviour, but LGTM with these changes applied.

@Rustin170506 Rustin170506 force-pushed the rustin-patch-bootstrap branch from b6d2cde to cd62f22 Compare June 27, 2023 02:02
@Rustin170506 Rustin170506 changed the title Use StringOrBool to set optimize Use RustOptimize to set optimize Jun 27, 2023
@Rustin170506 Rustin170506 force-pushed the rustin-patch-bootstrap branch from cd62f22 to ec19653 Compare June 27, 2023 02:02
@Rustin170506
Copy link
Member Author

  • Create an enum and call the methods on it. config.is_release() is a bit more "global", maybe it should be e.g. config.rust_opt.is_release() or something like that.
  • Perform the validation when creating the enum. When you now run bootstrap, but the get_opt_level method is not called (I'm not sure if it's called always), then you will not know that the provided value might be wrong. And then when you run a different command, suddenly it can fail.

Addressed.

I'd also like to ask if you can add a test to validate the new behaviour

Could you please give me some tips about how to add it? Or which test case I can refer to?

@Rustin170506
Copy link
Member Author

Thanks for your review! 💚 💙 💜 💛 ❤️

@Rustin170506
Copy link
Member Author

@clubby789 Friendly ping~ Could you please take a look? Thanks!

@clubby789
Copy link
Contributor

clubby789 commented Jun 30, 2023

Sorry for the wait - you can look at https://github.com/rust-lang/rust/blob/master/src/bootstrap/config/tests.rs for some examples of testing the config. The changes themselves look good 🙂

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@Rustin170506 Rustin170506 force-pushed the rustin-patch-bootstrap branch from ec19653 to 878eff1 Compare July 1, 2023 08:59
@Rustin170506
Copy link
Member Author

Rustin170506 commented Jul 1, 2023

Sorry for the wait - you can look at master/src/bootstrap/config/tests.rs for some examples of testing the config. The changes themselves look good 🙂

@clubby789 Added. Thanks! I have a small question: How can I run an individual test from the Bootstrap module? Now I only can use ./x.py test src/bootstrap to run all tests.

@rust-log-analyzer

This comment has been minimized.

@Rustin170506
Copy link
Member Author

It's a bit strange that I can pass the test locally. Is there some special configuration needed? Or is there something wrong with my test itself?

@clubby789
Copy link
Contributor

clubby789 commented Jul 1, 2023

parse_inner by default will look for a config.toml - you have one locally but the CI does not (or is different), so it has different behaviour. You can use the existing parse function in the test file

@clubby789
Copy link
Contributor

r=me with tests fixed
@bors delegate+

@bors
Copy link
Contributor

bors commented Jul 1, 2023

✌️ @hi-rustin, you can now approve this pull request!

If @clubby789 told you to "r=me" after making some further change, please make that change, then do @bors r=@clubby789

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@Rustin170506
Copy link
Member Author

parse_inner by default will look for a config.toml - you have one locally but the CI does not (or is different), so it has different behaviour. You can use the existing parse function in the test file

Got it. Thanks!

@Rustin170506
Copy link
Member Author

@bors r=@clubby789

@bors
Copy link
Contributor

bors commented Jul 2, 2023

📌 Commit 7cab8f7 has been approved by clubby789

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 2, 2023
@bors
Copy link
Contributor

bors commented Jul 2, 2023

⌛ Testing commit 7cab8f7 with merge be6e38c...

@bors
Copy link
Contributor

bors commented Jul 2, 2023

☀️ Test successful - checks-actions
Approved by: clubby789
Pushing be6e38c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 2, 2023
@bors bors merged commit be6e38c into rust-lang:master Jul 2, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jul 2, 2023
assert_eq!(parse("").rust_optimize.is_release(), true);
assert_eq!(parse("rust.optimize = false").rust_optimize.is_release(), false);
assert_eq!(parse("rust.optimize = true").rust_optimize.is_release(), true);
assert_eq!(parse("rust.optimize = \"1\"").rust_optimize.get_opt_level(), Some("1".to_string()));
Copy link
Member

@jyn514 jyn514 Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer to require this to be an int instead of a string, so rust.optimize = 1 instead of \"1\". no one is using the new config yet so i think we can break hard here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the "s" and "z"? Do you mean we need to use an IntOrString here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it later.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (be6e38c): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.8% [0.6%, 0.9%] 6
Regressions ❌
(secondary)
1.1% [0.4%, 1.4%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.8% [0.6%, 0.9%] 6

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.6% [0.5%, 2.4%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.0% [-3.4%, -0.6%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-3.4%, 2.4%] 5

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
-4.5% [-6.0%, -3.0%] 2
All ❌✅ (primary) -0.7% [-0.7%, -0.7%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 661.616s -> 662.143s (0.08%)

@rustbot rustbot added the perf-regression Performance regression. label Jul 2, 2023
@lqd
Copy link
Member

lqd commented Jul 2, 2023

diesel and wg-grammar noise

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bootstrap: Allow configuring the opt-level, not just debug vs release
9 participants